package gutils

import "time"

// 判断时间戳是否在今天的范围内
func TimeIsInTodayRange(timestamp int64) bool {
	startTimestamp, endTimestamp := GetDayRangeTimestamp(time.Now())
	return timestamp >= startTimestamp && timestamp <= endTimestamp
}

// 获取指定日期的开始时间戳结束时间戳
func GetDayRangeTimestamp(day time.Time) (startTimestamp, endTimestamp int64) {
	startOfDay, endOfDay := GetDayRange(day)

	startTimestamp = startOfDay.Unix()
	endTimestamp = endOfDay.Unix()

	return
}

func GetDay(dayNum int64) time.Time {
	return time.Now().Add(time.Duration(dayNum) * time.Hour)
}

// 获取指定日期的开始时间戳(含)和结束时间戳(不含)
func GetDayRange(day time.Time) (startTimestamp, endTimestamp time.Time) {
	startOfDay := time.Date(day.Year(), day.Month(), day.Day(), 0, 0, 0, 0, day.Location())
	endOfDay := startOfDay.AddDate(0, 0, 1).Add(-time.Nanosecond)

	return startOfDay, endOfDay
}
